from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-04-28 14:11:05.228807
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 28, Apr, 2021
Time: 14:11:09
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.8296
Nobs: 275.000 HQIC: -48.5383
Log likelihood: 3317.46 FPE: 5.17505e-22
AIC: -49.0133 Det(Omega_mle): 3.75236e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.419962 0.121104 3.468 0.001
L1.Burgenland 0.073556 0.060060 1.225 0.221
L1.Kärnten -0.225580 0.053235 -4.237 0.000
L1.Niederösterreich 0.088120 0.129459 0.681 0.496
L1.Oberösterreich 0.225720 0.124855 1.808 0.071
L1.Salzburg 0.267842 0.068878 3.889 0.000
L1.Steiermark 0.112316 0.087476 1.284 0.199
L1.Tirol 0.120475 0.060583 1.989 0.047
L1.Vorarlberg -0.035124 0.055587 -0.632 0.527
L1.Wien -0.038011 0.112316 -0.338 0.735
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.452211 0.140270 3.224 0.001
L1.Burgenland 0.003928 0.069565 0.056 0.955
L1.Kärnten 0.330490 0.061660 5.360 0.000
L1.Niederösterreich 0.102791 0.149947 0.686 0.493
L1.Oberösterreich -0.063663 0.144614 -0.440 0.660
L1.Salzburg 0.220787 0.079778 2.767 0.006
L1.Steiermark 0.092059 0.101320 0.909 0.364
L1.Tirol 0.138605 0.070171 1.975 0.048
L1.Vorarlberg 0.149990 0.064384 2.330 0.020
L1.Wien -0.417185 0.130091 -3.207 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.276945 0.061363 4.513 0.000
L1.Burgenland 0.102586 0.030432 3.371 0.001
L1.Kärnten -0.013122 0.026974 -0.486 0.627
L1.Niederösterreich 0.079414 0.065597 1.211 0.226
L1.Oberösterreich 0.282220 0.063264 4.461 0.000
L1.Salzburg 0.016890 0.034901 0.484 0.628
L1.Steiermark -0.000636 0.044324 -0.014 0.989
L1.Tirol 0.070468 0.030698 2.296 0.022
L1.Vorarlberg 0.075532 0.028166 2.682 0.007
L1.Wien 0.112629 0.056911 1.979 0.048
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.212292 0.058825 3.609 0.000
L1.Burgenland 0.027924 0.029174 0.957 0.338
L1.Kärnten 0.010524 0.025859 0.407 0.684
L1.Niederösterreich 0.052115 0.062884 0.829 0.407
L1.Oberösterreich 0.396918 0.060647 6.545 0.000
L1.Salzburg 0.078297 0.033457 2.340 0.019
L1.Steiermark 0.130587 0.042491 3.073 0.002
L1.Tirol 0.050048 0.029428 1.701 0.089
L1.Vorarlberg 0.081475 0.027001 3.018 0.003
L1.Wien -0.040665 0.054557 -0.745 0.456
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.488158 0.114953 4.247 0.000
L1.Burgenland 0.097161 0.057009 1.704 0.088
L1.Kärnten 0.010537 0.050531 0.209 0.835
L1.Niederösterreich 0.006049 0.122884 0.049 0.961
L1.Oberösterreich 0.124411 0.118513 1.050 0.294
L1.Salzburg 0.055620 0.065380 0.851 0.395
L1.Steiermark 0.065925 0.083033 0.794 0.427
L1.Tirol 0.207821 0.057506 3.614 0.000
L1.Vorarlberg 0.032739 0.052763 0.620 0.535
L1.Wien -0.081326 0.106612 -0.763 0.446
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.209217 0.090958 2.300 0.021
L1.Burgenland -0.011259 0.045110 -0.250 0.803
L1.Kärnten -0.007574 0.039984 -0.189 0.850
L1.Niederösterreich -0.017860 0.097234 -0.184 0.854
L1.Oberösterreich 0.418531 0.093776 4.463 0.000
L1.Salzburg 0.012252 0.051733 0.237 0.813
L1.Steiermark -0.027673 0.065702 -0.421 0.674
L1.Tirol 0.162312 0.045503 3.567 0.000
L1.Vorarlberg 0.057793 0.041750 1.384 0.166
L1.Wien 0.210080 0.084358 2.490 0.013
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.221690 0.110431 2.008 0.045
L1.Burgenland 0.020521 0.054767 0.375 0.708
L1.Kärnten -0.070294 0.048543 -1.448 0.148
L1.Niederösterreich -0.064733 0.118049 -0.548 0.583
L1.Oberösterreich 0.022616 0.113851 0.199 0.843
L1.Salzburg 0.081543 0.062807 1.298 0.194
L1.Steiermark 0.325283 0.079767 4.078 0.000
L1.Tirol 0.461719 0.055244 8.358 0.000
L1.Vorarlberg 0.144471 0.050688 2.850 0.004
L1.Wien -0.139751 0.102417 -1.365 0.172
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.208956 0.132037 1.583 0.114
L1.Burgenland 0.039960 0.065482 0.610 0.542
L1.Kärnten -0.075548 0.058041 -1.302 0.193
L1.Niederösterreich 0.111989 0.141146 0.793 0.428
L1.Oberösterreich 0.013742 0.136126 0.101 0.920
L1.Salzburg 0.195522 0.075096 2.604 0.009
L1.Steiermark 0.129623 0.095374 1.359 0.174
L1.Tirol 0.056073 0.066052 0.849 0.396
L1.Vorarlberg 0.106980 0.060605 1.765 0.078
L1.Wien 0.220908 0.122456 1.804 0.071
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.539390 0.072659 7.424 0.000
L1.Burgenland -0.014137 0.036034 -0.392 0.695
L1.Kärnten -0.015444 0.031940 -0.484 0.629
L1.Niederösterreich 0.099605 0.077671 1.282 0.200
L1.Oberösterreich 0.302425 0.074909 4.037 0.000
L1.Salzburg 0.013837 0.041325 0.335 0.738
L1.Steiermark -0.046589 0.052483 -0.888 0.375
L1.Tirol 0.081006 0.036348 2.229 0.026
L1.Vorarlberg 0.103615 0.033350 3.107 0.002
L1.Wien -0.059378 0.067386 -0.881 0.378
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.161394 0.092627 0.164782 0.220539 0.076157 0.087192 0.001423 0.156506
Kärnten 0.161394 1.000000 0.053608 0.209357 0.182781 -0.063982 0.175033 0.020447 0.305626
Niederösterreich 0.092627 0.053608 1.000000 0.245083 0.085137 0.320243 0.147984 0.021404 0.312254
Oberösterreich 0.164782 0.209357 0.245083 1.000000 0.304082 0.260394 0.097271 0.059606 0.138131
Salzburg 0.220539 0.182781 0.085137 0.304082 1.000000 0.151973 0.061778 0.089774 0.018278
Steiermark 0.076157 -0.063982 0.320243 0.260394 0.151973 1.000000 0.098076 0.099549 -0.102392
Tirol 0.087192 0.175033 0.147984 0.097271 0.061778 0.098076 1.000000 0.153207 0.155147
Vorarlberg 0.001423 0.020447 0.021404 0.059606 0.089774 0.099549 0.153207 1.000000 -0.009559
Wien 0.156506 0.305626 0.312254 0.138131 0.018278 -0.102392 0.155147 -0.009559 1.000000